package com.neusoft.elmboot.service.impl;

import com.neusoft.elmboot.util.EncryptUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.neusoft.elmboot.mapper.UserMapper;
import com.neusoft.elmboot.po.User;
import com.neusoft.elmboot.service.UserService;

@Service
public class UserServiceImpl implements UserService {

	@Autowired
	private UserMapper userMapper;

	@Override
	public User getUserByIdByPass(User user) {
		try {
			String id = user.getUserId();
			String str1 = user.getPassword();
			User user2 = userMapper.getUserById(id);
			String str2 = user2.getPassword();
			if(EncryptUtils.verifyBCryptHash(str1,str2)){
				return  user2;
			}else{
				return  null;
			}
		}catch (Exception e){
			return null;
		}

	}

	@Override
	public User getUserById(String userId) {
		return userMapper.getUserById(userId);
	}

	@Override
	public int saveUser(User user) {
		user.setPassword(EncryptUtils.getBCryptString(user.getPassword()));
		return userMapper.saveUser(user);
	}
}